package utils;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.FileHandler;
import java.util.logging.SimpleFormatter;

public final class LogUtils {

    public final static Logger getLogger(String logname, String filename)
            throws IOException {
        Logger      logger = Logger.getLogger(logname);
        FileHandler fh     = null;

        try {
            fh = new FileHandler(filename);
            fh.setFormatter(new SimpleFormatter());
        } catch (IOException e) {
            if (fh != null) {
                fh.close();
            }
            throw new IOException(e);
        } catch (SecurityException e) {
            if (fh != null) {
                fh.close();
            }
            throw new SecurityException(e);
        }

        logger.addHandler(fh);
        logger.setLevel(Level.ALL);

        return logger;
    }

}
